package cn.wolfcode.crm.util;

import lombok.Getter;
import lombok.Setter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter@Getter
public abstract class GetMouth {
    /*获取当月第一和最后一天日期*/
    public static Map<String,Date> getMouth() throws ParseException {
        Calendar cale = Calendar.getInstance();
        // 获取当月第一天和最后一天
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        // 获取前月的第一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        cale.set(Calendar.DAY_OF_MONTH, 1);
        String firstday = format.format(cale.getTime());
        Date firstdate = format.parse(firstday);
        // 获取前月的最后一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 1);
        cale.set(Calendar.DAY_OF_MONTH, 0);
        String lastday = format.format(cale.getTime());
        Date lastdate = format.parse(lastday);


        Map<String,Date> dates = new HashMap<>();
        dates.put("firstday",firstdate);
        dates.put("lastday",lastdate);
        return dates;
    }
}
